//
//  HYFillLabel.m
//  HaiYue
//
//  Created by skyline on 2017/12/28.
//  Copyright © 2017年 skyline. All rights reserved.
//

#import "HYFillLabel.h"
#import "HYLabel.h"
NSString * const HYTextColor = @"HYTEXTCOLOR";
NSString * const HYLayerColor = @"HYLAYERCOLOR";
NSString * const HYBorderColor = @"HYBORDERCOLOR";
NSString * const HYTextFont = @"HYTEXTFONT";
@interface HYFillLabel ()
@property (nonatomic, strong) UIColor *textColor;
@property (nonatomic, strong) UIFont *font;
@property (nonatomic, strong) HYLabel *label;
@end
@implementation HYFillLabel
- (instancetype)initWithFrame:(CGRect)frame typeOfshapeLayer:(CCShapeLayerType)type attribute:(NSDictionary *)att
{
    self = [super initWithFrame:frame];
    if (self)
    {
        self.bounds = CGRectMake(0, 0, frame.size.width, frame.size.height);
        CCShapeLayer *shaper = [[CCShapeLayer alloc]initWithFrame:frame];
        shaper.strokeColor = ORANGE_COLOR.CGColor;
        shaper.fillColor = ORANGE_COLOR.CGColor;
        shaper.type = type;
        shaper.lineWidth = 0.2;
        shaper.strokeColor = ([att valueForKey:HYLayerColor])?[[att valueForKey:HYLayerColor] CGColor]:shaper.strokeColor;
        shaper.fillColor = ([att valueForKey:HYBorderColor])?[[att valueForKey:HYBorderColor] CGColor]:shaper.fillColor;
        self.textColor = ([att valueForKey:HYTextColor])?[att valueForKey:HYTextColor]:self.textColor;
        self.font = ([att valueForKey:HYTextFont])?[att valueForKey:HYTextFont]:self.font;
        [self.layer addSublayer:shaper];
    }
    return self;
}
- (HYLabel *)label
{
    if (!_label)
    {
        _label = [[HYLabel alloc]initWithText:@"" textColor:self.textColor textFont:self.font];
        _label.textAlignment = NSTextAlignmentCenter;
        [self addSubview:_label];
        [_label mas_updateConstraints:^(MASConstraintMaker *make) {
            make.center.equalTo(self);
        }];
    }
    return _label;
}
- (void)setText:(NSString *)text
{
    self.label.text = text;
}
/*
 // Only override drawRect: if you perform custom drawing.
 // An empty implementation adversely affects performance during animation.
 - (void)drawRect:(CGRect)rect {
 // Drawing code
 }
 */

@end
